<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-2-27
 */

namespace Zhub\Prototype\Objective\Clazz\Property;


use Zhub\DataStruct\Struct;
use Zhub\Prototype\Objective\Clazz\ClassUtils;
use Zhub\Prototype\Objective\Clazz\ClazzEnum;
use Zhub\Prototype\Objective\Clazz\ClazzUtil;

class PropertyStruct extends Struct
{
    const ACCESS = 'access';

    const STATIC = 'static';

    const NAME = 'name';

    const DEFAULT_VALUE = 'defaultValue';

    public static function initialize(): array
    {
        return [
            self::ACCESS => ClazzEnum::ACCESS_PUBLIC,
            self::STATIC => false,
            self::NAME => '',
            self::DEFAULT_VALUE => null,
        ];
    }

    public function getAccess():int
    {
        return $this->get(self::ACCESS);
    }

    public function setAccess(int $access)
    {
        $this->set(self::ACCESS, $access);
    }

    public function getStatic():bool
    {
        return $this->get(self::STATIC);
    }

    public function setStatic(bool $static)
    {
        $this->set(self::STATIC, $static);
    }

    public function getName():string
    {
        return $this->get(self::NAME);
    }

    public function setName(string $name)
    {
        ClazzUtil::checkName($name);
        $this->set(self::NAME, $name);
    }

    public function getDefaultValue()
    {
        return $this->get(self::DEFAULT_VALUE);
    }

    public function setDefaultValue($defaultValue)
    {
        $this->set(self::DEFAULT_VALUE, $defaultValue);
    }

    public function toString(): string
    {
        $defaultValue = var_export($this->getDefaultValue(), true);
        if ($defaultValue == 'NULL') {
            $defaultValue = strtolower($defaultValue);
        }
        return ClazzEnum::name($this->getAccess()) .
            ($this->getStatic() ? ' ' . ClazzEnum::name(ClazzEnum::STATIC) : '') . ' $' .
            $this->getName() . ' = ' . $defaultValue . ';';
    }

}